# -*- coding: utf-8 -*-
# @Time : 2019/1/11 9:27
# @Author : Administrator
# @File : employment.py
# @Project : python
# @title : 接口测试 -- 学员管理
import ddt
import unittest,random
from woniuboss_interface.util.read_data import Read_Excel
from woniuboss_interface.common.login_decode import Login
data_li = Read_Excel()
a,host,excel_path = Login()

@ddt.ddt
class modify(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print("测试开始")

    @ddt.data(*data_li.excel(excel_path,4))
    def test_student_mod(self,data):  ## 学员管理修改
        result=a.post(url=host+"/student/saveNewInfo",#Content-Type: multipart/form-data
                            files={
                                'stu.student_id':(None,'1274'),
                                'stu.student_name': (None,data['name']),
                                'stu.student_no':(None,data['number']),
                                'class_no': (None,'WNCDC034'),
                                'stu.tel': (None, data['phone']),
                                'stu.sex':(None,data['sex']),
                                'stu.status':(None,'在校学习'),
                                'stu.email':(None,''),
                                'stu.QQ':(None,'0'),
                                'stu.source':(None,'智联招聘'),
                                'stu.emergency_person':(None,'18510295804'),
                                'stu.emergency_tel':(None,'13350022197'),
                                'stu.school':(None,'重庆市城市职业学院'),
                                'stu.education':(None,'本科'),
                                'stu.major':(None,'应用化学'),
                                'stu.IDnumber':(None,data['idcard']),
                                'stu.graduation_time':(None,'2016-05-12'),
                                'stu.age':(None,'23'),
                                "img": (open("../../woniuboss_interface/data/test.png", mode="rb"))}
                           )
        self.assertIn(data['expect'],result.text)

    @ddt.data(*data_li.excel(excel_path,5))
    def test_add(self,data):   ## 学员新增请假
        con=a.post(url=host+"/student/saveLeave",
                    data={'sl.student_id':data['sl.student_id'],
                          'sl.start_time':data['sl.start_time'],
                          'sl.end_time':data['sl.end_time'],
                          'sl.leave_type':data['sl.leave_type'],
                          'sl.days':data['sl.days'],
                          'stuName':data['stuName'],
                          'sl.reason':data['sl.reason'],
                          'sl.comment':data['sl.comment']
                          })
        self.assertEqual(data['expect'],con.text)

    @ddt.data(*data_li.excel(excel_path,6))
    def test_add(self,data):  ## 学员管理阶段测评
        con=a.post(url=host+"/student/saveScore",
                    data={'pe.phase_exam_student_id':data['pe.phase_exam_student_id'],
                          'pe_orientation1':data['pe_orientation1'],
                          'pe_class1':data['pe_class1'],
                          'pe.phase':data['pe.phase'],
                          'pe.score':data['pe.score'],
                          'status':data['status'],
                          'pe.comment':data['pe.comment']
                          })
        self.assertIn(data['expect'],con.text)

    def test_Stagevaluation(self):
        result=self.decode01()
        if result==True:
            note=str(random.randint(1,99999999999999999))
            url=host+'/student/saveScore'
            data={"pe.phase_exam_student_id":"846",
                  "pe_orientation1":"",
                  "pe_class1":"",
                  "pe.phase":"专业第一阶段",
                  "pe.score":"88",
                  "status":"1",
                  "pe.comment":"%s"%note}
            c=a.post(url=url,data=data)
            self.assertEqual(c.text,"success")
        else:
            print("未解密")

    def test_demotion(self):
        url =host+'/student/updateRepeat'
        data={"pe.phase_exam_student_id":"843","old_re_orientation":"%E5%BC%80%E5%8F%91","old_re_class":"WNCQC006","orientation":"%E6%B5%8B%E8%AF%95","class_no":"WNCDC035"}
        c=a.post(url=url,data=data)
        print(c.text)

    def decode01(self):
        url = host+'/student/queryPhaseExamStuByInfo'
        data={"pageSize":"10","pageIndex":"1","stuClass":"","orientation":"","stuName":""}
        c=a.post(url=url,data=data)
        # print(c.text)
        if '****' in c.text:
            result=False
        else:
            result=True

        return result

    @classmethod
    def tearDownClass(cls):
            print("测试结束")

if __name__ == '__main__':
    unittest.main()